-
-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for type checked term_at<T> and term_at<T>(i) #1397
base: master
Are you sure you want to change the base?
Conversation
5a80df7
to
ac73c71
Compare
Would it make sense to have the parameter-less |
Maybe just .term<>() and then also add .term(flecs::entity_t component) to match other apis? |
ac73c71
to
0a9e0af
Compare
0a9e0af
to
c1b556a
Compare
Renamed term_at to term. Also updated the logic to account for pairs properly |
72e7ea1
to
fe2c902
Compare
Looks like I cant use term as it fails on build here so changing back to term_at I guess: https://github.com/SanderMertens/flecs/actions/runs/11327040474/job/31497292704?pr=1397 |
fe2c902
to
d9a0a6d
Compare
d9a0a6d
to
7adca4c
Compare
First method is simple loop over terms to find term for T. Its slower than using index directly, but sometimes type safety is more preferred and when the cost is only on initialization. Second method is same as term_at(i) but with type checked assert. For middle ground to still keep the safety but also performance. This is mostly to mirror the C# binding PR where this is slightly more useful but maybe cpp would benefit too: BeanCheeseBurrito/Flecs.NET#52 Signed-off-by: Tomas Slusny <[email protected]>
7adca4c
to
ad60d47
Compare
First method is simple loop over terms to find term for T. Its slower than using index directly, but sometimes type safety is more preferred and when the cost is only on initialization.
Second method is same as term_at(i) but with type checked assert. For middle ground to still keep the safety but also performance.
This is mostly to mirror the C# binding PR where this is slightly more useful but maybe cpp would benefit too:
BeanCheeseBurrito/Flecs.NET#52
Also disclaimer, I dont rly work with cpp often so I might've easily missed something, but I made best effort to write some tests and at least run them and see if they pass :d
Example use:
Current method
world.System<Position, Velocity>() .term_at(1) .singleton();
Type checked (throws assert if term_at(1) isnt Velocity type)
world.System<Position, Velocity>() .term_at<Velocity>(1) .singleton();
Type checked + resolved (throws assert if there is no Velocity component):